package com.wu.web;

import com.alibaba.fastjson.JSON;
import com.wu.bean.Journal;
import com.wu.service.JournalService;
import com.wu.service.impl.JournalServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/UpdateJournal")
public class UpdateJournalServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String content=req.getParameter("content");
        String title=req.getParameter("title");
        int category=Integer.parseInt(req.getParameter("category"));
        HttpSession session=req.getSession();
        int id=Integer.parseInt(session.getAttribute("Journalid").toString());

        JournalService journalService=new JournalServiceImpl();
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        int ok=journalService.UpdateLog(new Journal(id,title,content,null,null,category,0,0));
        if(ok>0)
        resp.getWriter().print("ok");
        else
            resp.getWriter().print("no");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
